home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / common / exp.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  5KB  |  186 lines

  1. /*
  2.  * static char *rcsid_arch_c =
  3.  *   "$Id: exp.c,v 1.4 1994/04/16 00:02:48 master Exp $";
  4.  */
  5.  
  6. /*
  7.     CrossFire, A Multiplayer game for X-windows
  8.  
  9.     Copyright (C) 1992 Frank Tore Johansen
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.     The author can be reached via e-mail to frankj@ifi.uio.no.
  26. */
  27. #include <stdio.h>
  28. #include <global.h>
  29.  
  30. #define TRUE    1
  31. #define FALSE    0
  32.  
  33. float exp_att_mult[NROFATTACKS+2] = {
  34.     0.0,                /* AT_PHYSICAL    */
  35.     0.0,                /* AT_MAGIC    */
  36.     0.0,                /* AT_FIRE    */
  37.     0.0,                /* AT_ELECTRICITY */
  38.     0.0,                /* AT_COLD    */
  39.     0.0,                /* AT_WATER    *//*AT_CONFUSION!*/
  40.     0.4,                /* AT_ACID    */
  41.     1.5,                /* AT_DRAIN    */
  42.     0.0,                /* AT_WEAPONMAGIC */
  43.     0.1,                /* AT_GHOSTHIT    */
  44.     0.3,                /* AT_POISON    */
  45.     0.2,                /* AT_DISEASE    */
  46.     0.3,                /* AT_PARALYZE    */
  47.     0.0,                /* AT_TURN_UNDEAD */
  48.     0.0,                /* AT_FEAR    */
  49.     0.0,                /* AT_CANCELLATION */
  50.     0.0,                /* AT_DEPLETE */
  51.     0.0,                /* AT_DEATH */
  52.     0.0,                /* AT_CHAOS */
  53.     0.0                /* AT_COUNTERSPELL */
  54. };
  55.  
  56. float exp_prot_mult[NROFATTACKS+2] = {
  57.     0.4,                /* AT_PHYSICAL    */
  58.     0.5,                /* AT_MAGIC    */
  59.     0.1,                /* AT_FIRE    */
  60.     0.1,                /* AT_ELECTRICITY */
  61.     0.1,                /* AT_COLD    */
  62.     0.1,                /* AT_WATER    */
  63.     0.1,                /* AT_ACID    */
  64.     0.1,                /* AT_DRAIN    */
  65.     0.1,                /* AT_WEAPONMAGIC */
  66.     0.1,                /* AT_GHOSTHIT    */
  67.     0.1,                /* AT_POISON    */
  68.     0.1,                /* AT_DISEASE    */
  69.     0.1,                /* AT_PARALYZE    */
  70.     0.1,                /* AT_TURN_UNDEAD */
  71.     0.1,                /* AT_FEAR    */
  72.     0.0,                /* AT_CANCELLATION */
  73.     0.0,                /* AT_DEPLETE */
  74.     0.0,                /* AT_DEATH */
  75.     0.0,                /* AT_CHAOS */
  76.     0.0                /* AT_COUNTERSPELL */
  77.  
  78. };
  79.  
  80. float exp_imm_mult[NROFATTACKS+2] = {
  81.     0.5,                /* AT_PHYSICAL    */
  82.     1.0,                /* AT_MAGIC    */
  83.     0.2,                /* AT_FIRE    */
  84.     0.2,                /* AT_ELECTRICITY */
  85.     0.2,                /* AT_COLD    */
  86.     0.2,                /* AT_WATER    */
  87.     0.2,                /* AT_ACID    */
  88.     0.2,                /* AT_DRAIN    */
  89.     0.2,                /* AT_WEAPONMAGIC */
  90.     0.2,                /* AT_GHOSTHIT    */
  91.     0.2,                /* AT_POISON    */
  92.     0.2,                /* AT_DISEASE    */
  93.     0.2,                /* AT_PARALYZE    */
  94.     0.2,                /* AT_TURN_UNDEAD */
  95.     0.2,                /* AT_FEAR    */
  96.     0.0,                /* AT_CANCELLATION */
  97.     0.0,                /* AT_DEPLETE */
  98.     0.0,                /* AT_DEATH */
  99.     0.0,                /* AT_CHAOS */
  100.     0.0                /* AT_COUNTERSPELL */
  101.  
  102. };
  103.  
  104. float exp_vuln_mult[NROFATTACKS+2] = {
  105.     0.8,                /* AT_PHYSICAL    */
  106.     0.8,                /* AT_MAGIC    */
  107.     0.9,                /* AT_FIRE    */
  108.     0.9,                /* AT_ELECTRICITY */
  109.     0.9,                /* AT_COLD    */
  110.     0.99,                /* AT_WATER    */
  111.     0.9,                /* AT_ACID    */
  112.     0.9,                /* AT_DRAIN    */
  113.     0.9,                /* AT_WEAPONMAGIC */
  114.     0.9,                /* AT_GHOSTHIT    */
  115.     0.9,                /* AT_POISON    */
  116.     0.9,                /* AT_DISEASE    */
  117.     0.9,                /* AT_PARALYZE    */
  118.     0.9,                /* AT_TURN_UNDEAD */
  119.     0.9,                /* AT_FEAR    */
  120.     0.0,                /* AT_CANCELLATION */
  121.     0.0,                /* AT_DEPLETE */
  122.     0.0,                /* AT_DEATH */
  123.     0.0,                /* AT_CHAOS */
  124.     0.0                /* AT_COUNTERSPELL */
  125.  
  126. };
  127.  
  128. /*
  129.  * nex_exp() is an alternative way to calculate experience based
  130.  * on the ability of a monster.
  131.  * It's far from perfect, and doesn't consider everything which
  132.  * can be considered, thus it's only used in debugging.
  133.  */
  134.     
  135. int new_exp(object *ob) {
  136.   double    att_mult, prot_mult, imm_mult, vuln_mult, spec_mult;
  137.   double    exp;
  138.   int        i;
  139.   long        mask = 1;
  140.  
  141.   att_mult = prot_mult = imm_mult = vuln_mult = spec_mult = 1.0;
  142.   for(i=0;i<NROFATTACKS+2;i++) {
  143.     att_mult += (exp_att_mult[i] * ((ob->attacktype&mask) != FALSE));
  144.     prot_mult += (exp_prot_mult[i] * ((ob->protected&mask) != FALSE));
  145.     imm_mult += (exp_imm_mult[i] * ((ob->immune&mask) != FALSE));
  146.     vuln_mult *= (ob->vulnerable&mask) ? exp_vuln_mult[i] : 1.0;
  147.     mask <<= 1;
  148.   }
  149.   spec_mult +=     (0.3*(QUERY_FLAG(ob,FLAG_SEE_INVISIBLE)!= FALSE)) +
  150.           (0.5*(QUERY_FLAG(ob,FLAG_SPLITTING)!= FALSE))+
  151.         (0.3*(QUERY_FLAG(ob,FLAG_HITBACK)!= FALSE)) + 
  152.         (0.1*(QUERY_FLAG(ob,FLAG_REFL_MISSILE)!= FALSE)) +
  153.         (0.3*(QUERY_FLAG(ob,FLAG_REFL_SPELL)!= FALSE)) +
  154.         (1.0*(QUERY_FLAG(ob,FLAG_NO_MAGIC)!= FALSE)) +
  155.         (0.1*(QUERY_FLAG(ob,FLAG_PICK_UP)!= FALSE)) + 
  156.         (0.1*(QUERY_FLAG(ob,FLAG_USE_SCROLL)!= FALSE)) +
  157.         (0.2*(QUERY_FLAG(ob,FLAG_USE_WAND)!= FALSE)) +
  158.         (0.1*(QUERY_FLAG(ob,FLAG_USE_BOW)!= FALSE)) +
  159.         (0.1*(ob->can_apply != FALSE));
  160.   exp = (ob->stats.maxhp<5) ? 5 : ob->stats.maxhp;
  161.   exp *= (QUERY_FLAG(ob,FLAG_CAST_SPELL) && has_ability(ob)) 
  162.        ? (40+(ob->stats.maxsp>80?80:ob->stats.maxsp))/40 : 1;
  163.   exp *= (80.0/(70.0+ob->stats.wc)) * (80.0/(70.0+ob->stats.ac)) * (50.0+ob->stats.dam)/50.0;
  164.   exp *= att_mult * prot_mult * imm_mult * vuln_mult * spec_mult;
  165.   exp *= 2.0/(2.0-((FABS(ob->speed)<0.95)?FABS(ob->speed):0.95));
  166.   exp *= (20.0+ob->stats.Con)/20.0;
  167.   if (QUERY_FLAG(ob, FLAG_STAND_STILL))
  168.     exp /= 2;
  169.  
  170.   return (int) exp;
  171. }
  172.  
  173. /*
  174.  * Returns true if the monster specified has any innate abilities.
  175.  */
  176.  
  177. int has_ability(object *ob) {
  178.   object *tmp;
  179.  
  180.   for(tmp=ob->inv;tmp!=NULL;tmp=tmp->below)
  181.     if(tmp->type==ABILITY||tmp->type==SPELLBOOK) 
  182.       return TRUE;
  183.  
  184.   return FALSE;
  185. }
  186.